home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE09
/
FILES
/
NETLOCK.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-04-09
|
3KB
|
100 lines
unit NetLock;
interface
uses
WinTypes, WinProcs;
{ Core routines that mimic Win32 parameter set }
{$ifndef Win32}
function LockFile(Handle: Integer; FileOffsetLow, FileOffsetHigh,
LockBytesLow, LockBytesHigh: Integer): Bool;
function UnlockFile(Handle: Integer; FileOffsetLow, FileOffsetHigh,
LockBytesLow, LockBytesHigh: Integer): Bool;
{$endif}
{ Handle based routine that un/locks a given number of bytes }
function LockFileArea(Handle: Integer; FileOffset, LockBytes: Longint;
Unlock: Boolean): Bool;
{ File variable based routine that un/locks a given number of records }
function LockFileVarArea(var FileVar; RecordNumber, NumRecords: Longint;
Unlock: Boolean): Bool;
{ File variable based routine that un/locks one record }
function LockFileVar(var FileVar; RecordNumber: Longint;
Unlock: Boolean): Bool;
implementation
uses
SysUtils;
{$ifndef Win32}
{ Core routines that mimic Win32 parameter set }
function LockFile(Handle: Integer; FileOffsetLow, FileOffsetHigh,
LockBytesLow, LockBytesHigh: Integer): Bool; assembler;
asm
mov ah, $5C
mov al, 0
mov bx, Handle
mov cx, FileOffsetHigh
mov dx, FileOffsetLow
mov si, LockBytesHigh
mov di, LockBytesLow
int $21
jnc @1
xor ax, ax
jmp @2
@1:
mov ax, 1
@2:
end;
function UnlockFile(Handle: Integer; FileOffsetLow, FileOffsetHigh,
LockBytesLow, LockBytesHigh: Integer): Bool; assembler;
asm
mov ah, $5C
mov al, 1
mov bx, Handle
mov cx, FileOffsetHigh
mov dx, FileOffsetLow
mov si, LockBytesHigh
mov di, LockBytesLow
int $21
jnc @1
xor ax, ax
jmp @2
@1:
mov ax, 1
@2:
end;
{$endif}
{ Handle based routine that un/locks a given number of bytes }
function LockFileArea(Handle: Integer; FileOffset, LockBytes: Longint;
Unlock: Boolean): Bool;
begin
if not Unlock then
Result := LockFile(Handle, LoWord(FileOffset),
HiWord(FileOffset), LoWord(LockBytes), HiWord(LockBytes))
else
Result := UnlockFile(Handle, LoWord(FileOffset),
HiWord(FileOffset), LoWord(LockBytes), HiWord(LockBytes));
end;
{ File variable based routine that un/locks a given number of records }
function LockFileVarArea(var FileVar; RecordNumber, NumRecords: Longint;
Unlock: Boolean): Bool;
begin
with TFileRec(FileVar) do
Result := LockFileArea(Handle, Recordnumber * RecSize,
NumRecords * RecSize, Unlock);
end;
{ File variable based routine that un/locks one record }
function LockFileVar(var FileVar; RecordNumber: Longint;
Unlock: Boolean): Bool;
begin
Result := LockFileVarArea(FileVar, RecordNumber, 1, Unlock);
end;
end.